/**
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.api.adwords.starterkit.settings;

import com.google.api.adwords.starterkit.db.structures.CriterionStructure;
import com.google.api.adwords.starterkit.db.structures.KeywordStructure;
import com.google.api.adwords.v201101.cm.KeywordMatchType;
import com.google.api.adwords.v201101.cm.UserStatus;

/**
 * The Class KeywordSettings keeps all settings related to Keywords.
 * 
 * @author rodrigo.f.vale@gmail.com (Rodrigo Vale)
 */
public class KeywordSettings {
  private boolean autoPauseKeyword = true;
  private long cpc;
  private long cpm;
  private UserStatus keywordDefaultStatus;
  private KeywordMatchType defaultMatchType;
  private boolean syncBid = true;
  private boolean syncStatus = true;
  private boolean syncUrl = true;
  private boolean autoCreation = true;

  /**
   * Instantiates a new keyword settings.
   * 
   * @param autoPauseKeyword the auto pause keyword
   * @param cpc the keyword default cpc
   * @param cpm the keyword default cpm
   * @param keywordDefaultStatus the keyword default status
   * @param defaultMatchType the default match type
   * @param syncBid the sync bid
   * @param syncStatus the sync status
   * @param syncUrl the sync url
   * @param autoCreation flag that allows starterkit to create new keywords
   */
  public KeywordSettings(boolean autoPauseKeyword, long cpc, long cpm,
      UserStatus keywordDefaultStatus, KeywordMatchType defaultMatchType, 
      boolean syncBid, boolean syncStatus, boolean syncUrl, 
      boolean autoCreation) {
    this.autoPauseKeyword = autoPauseKeyword;
    this.cpc = cpc;
    this.setCpm(cpm);
    this.keywordDefaultStatus = keywordDefaultStatus;
    this.defaultMatchType = defaultMatchType;
    this.syncBid = syncBid;
    this.syncStatus = syncStatus;
    this.syncUrl = syncUrl;
    this.setAutoCreation(autoCreation);
  }

  public KeywordSettings() {
  }

  /**
   * sets the auto pause Keyword flag. This flag controls if Starter Kit can
   * pause Keywords automatically. A Keyword is paused automatically when it
   * is present at the AdWords system, but the application do not mention it. 
   * See the demos for a better understanding of it or the AutoPause session in 
   * the manual.
   */
  public void setAutoPause(boolean autoPause) {
    this.autoPauseKeyword = autoPause;
  }

  public boolean getAutoPause() {
    return this.autoPauseKeyword;
  }

  public void setCpc(long cpc) {
    this.cpc = cpc;
  }

  public long getCpc() {
    return this.cpc;
  }

/*  
  public void setStatus(UserStatus keywordDefaultStatus) {
    this.keywordDefaultStatus = keywordDefaultStatus;
  }
*/
  
  public void setStatus(String status) {
    status = status.toUpperCase();
    KeywordStructure.validateMatchType(status);
    this.keywordDefaultStatus = UserStatus.fromString(status);
  }
  
  
  public UserStatus getStatus() {
    return this.keywordDefaultStatus;
  }

  public void setMatchType(KeywordMatchType defaultMatchType) {
    this.defaultMatchType = defaultMatchType;
  }
  
  public void setMatchType(String defaultMatchType) {
    defaultMatchType = defaultMatchType.toUpperCase();
    CriterionStructure.validateMatchType(defaultMatchType);
    this.defaultMatchType = KeywordMatchType.fromString(defaultMatchType);
  }
  
  public KeywordMatchType getMatchType() {
    return this.defaultMatchType;
  }

  /**
   * Sets the can modify bid flag. If set to false, StarterKit will not
   * modify the bid of a Keyword even when direct requested by application.
   * See the canModifyXXXFlags at the manual for a deep dive explanation. 
   */
  public void setCanModifyBid(boolean syncBid) {
    this.syncBid = syncBid;
  }

  public boolean getCanModifyBid() {
    return syncBid;
  }

  /**
   * Sets the can modify Status flag. If set to false, StarterKit will not
   * modify the Status of a Keyword even when direct requested by application.
   * See the canModifyXXXFlags at the manual for a deep dive explanation. 
   */
  public void setCanModifyStatus(boolean syncStatus) {
    this.syncStatus = syncStatus;
  }

  public boolean getCanModifyStatus() {
    return syncStatus;
  }

  /**
   * Sets the can modify URL flag. If set to false, StarterKit will not
   * modify the URL of a Keyword even when direct requested by application.
   * See the canModifyXXXFlags at the manual for a deep dive explanation. 
   */
  public void setCanModifyUrl(boolean syncUrl) {
    this.syncUrl = syncUrl;
  }

  public boolean getCanModifyUrl() {
    return syncUrl;
  }

  /**
   * Sets the auto creation Keywords flag. This flag controls if Starter Kit 
   * can create new Keywords. Set to false to make sure that
   * the framework will not create any new Keyword even if requested by
   * the application.
   */
  public void setAutoCreation(boolean autoCreation) {
    this.autoCreation = autoCreation;
  }

  public boolean getAutoCreation() {
    return autoCreation;
  }

  public void setCpm(long cpm) {
    this.cpm = cpm;
  }

  public long getCpm() {
    return cpm;
  }
}